package com.zm.rpc.server.serializer;

import com.alibaba.fastjson2.JSON;

public class JsonSerializer implements ISerializer{

    @Override
    public <T> byte[] serialize(T obj) {
        if(obj == null){
            return null;
        }

        return JSON.toJSONBytes(obj);
    }

    @Override
    public <T> T deserialize(byte[] data, Class<T> clazz) {
        if(data == null || data.length == 0){
            return null;
        }
        return JSON.toJavaObject(new String(data), clazz);
    }

 
    
}
